<!DOCTYPE html>
<html>

  <head>
    <meta charset="UTF-8">
    <title>yaml Template add</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/static/super_cmdb/css/font.css">
    <link rel="stylesheet" href="/static/super_cmdb/css/xadmin.css">

    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>
    <div class="x-body layui-anim layui-anim-up">
        <form class="layui-form">

            <div class="layui-form-item">
              <label for="name" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>模板名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="name" name="name" required="" lay-verify="nikename"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>例：游戏服模板
              </div>
            </div>

            <div class="layui-form-item">
              <label for="content" class="layui-form-label" style="width: 120px">
                  <span class="x-red">*</span>模板内容
              </label>
              <div class="layui-input-inline">
                  <textarea type="text" id="content" name="content" style="width: 1200px; height: 550px; background-color: black;color: greenyellow;font-size: 15px;line-height: 18px"> 模板中需要替换的变量:

1.与server_id相关的数字用 9999，例如 name: peas15 === name: peas9999
2.Service处对外的端口号用 aaaa，bbbb，cccc...依次类推，添加时程序会生成3000x，3100x，3200x...的端口
apiVersion: v1
kind: Service
metadata:
  labels:
    app: peas9999
  name: peas9999
  namespace: peas
spec:
  ports:
  - port: 5112
    protocol: TCP
    targetPort: 5112
    nodePort: aaaa
    name: gameport
  - port: 5212
    protocol: TCP
    targetPort: 5212
    nodePort: bbbb
    name: gmport
  selector:
    app: peas16
  type: NodePort
                  </textarea>
              </div>
            </div>

            <hr>
            <div class="layui-form-item" >
              <label for="L_repass" class="layui-form-label" style="width: 120px">
              </label>
              <button class="layui-btn" lay-filter="yaml_add" lay-submit="">
                  提交
              </button>
            </div>
      </form>
    </div>
    <script type="text/javascript" src="/static/super_cmdb/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/super_cmdb/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/super_cmdb/js/xadmin.js"></script>
    <script type="text/javascript" src="/static/super_cmdb/js/jquery.cookie.js"></script>

        <script>
        $(function () {
            $.ajaxSetup({
                beforeSend: function (xhr, settings) {
                    xhr.setRequestHeader("X-CSRFtoken", $.cookie("csrftoken"));
                }
            })
        });

        layui.use(['form','layer'], function() {
            $ = layui.jquery;
            var form = layui.form
                , layer = layui.layer;

            //自定义验证规则
            form.verify({
                nikename: function (value) {
                    if (value.length < 1) {
                        return '昵称至少得1个字符啊';
                    }
                }
                , pass: [/(.+){6,12}$/, '密码必须6到12位']
                , repass: function (value) {
                    if ($('#L_pass').val() != $('#L_repass').val()) {
                        return '两次密码不一致';
                    }
                }
            });

            form.on('submit(yaml_add)', function (data) {
                console.log(data);
                var name = $("#name").val();
                var content = $("#content").val();

                if (name == ""){
                    alert("请填写模板名称!");
                    return false;
                }
                layer.confirm('确认添加' + name,function(index) {
                    //发异步删除数据
                    //layer.msg("部署中，勿做其他操作，请等待......", {icon: 1, time: 8000000});
                    $.ajax({
                        url: "/k8s/yaml_Template_add/",
                        type: "POST",
                        data: {
                            "name": name,
                            "content": content
                        },
                        success: function (data) {
                            if (data.code == 0) {
                                layer.alert(data.msg, {icon: 6,time:8000});
                            } else {
                                layer.alert(data.msg, {icon: 7,time:8000});
                            }
                        }
                    });
                    //layer.msg("装服任务已放在后台执行,可继续安装新服",{icon:1,time:8000});
                });
                return false;
            });
        });
    </script>

  </body>

</html>
